﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiFLEXCableEditorWindow
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Flexibles;
using EngineeringInternalExtension;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Markup;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands;

public class CUiFLEXCableEditorWindow : 
  TxWindow,
  INotifyPropertyChanged,
  ICApFLEXFrameSelection,
  ICApFLEXCableEditorSelection,
  IComponentConnector
{
  private CApCableFrameAttachmentRetriever m_frameAttachmentRetriever = new CApCableFrameAttachmentRetriever();
  private const double ParameterEpsilon = 0.0001;
  private ITxCable m_cableEditorObject;
  internal CUiFLEXCableEditorWindow dMainDialog;
  internal Grid createCableGrid;
  internal RowDefinition cableNameRow;
  internal TextBlock labelCableName;
  internal TxObjEditBoxControl txEditorName;
  internal TextBlock labelCableStartFrame;
  internal Grid startFrameGrid;
  internal TxObjEditBoxControl frameBoxCtrlStartFrameCable;
  internal System.Windows.Controls.Button editStartAttachmentFrame;
  internal TextBlock labelCableEndFrame;
  internal Grid endFrameGrid;
  internal TxObjEditBoxControl frameBoxCtrlEndFrameCable;
  internal System.Windows.Controls.Button editEndAttachmentFrame;
  internal TextBlock labelCableLength;
  internal TxNumericEditBoxControl TxNumericEditBoxLength;
  internal TextBlock labelCableRadius;
  internal TxNumericEditBoxControl TxNumericEditBoxRadius;
  internal Expander ExpanderParameters;
  internal CApCableParametersUserControl ParametersUserControl;
  internal Expander ExpanderAttachments;
  internal CApCableAttachmentsUserControl AttachmentsUserControl;
  internal System.Windows.Controls.Button btnGenerate;
  internal System.Windows.Controls.Button btnClose;
  internal System.Windows.Controls.Image iMessageType;
  internal TextBlock tbMessage;
  private bool _contentLoaded;

  [DllImport("user32.dll")]
  private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

  [DllImport("user32.dll")]
  private static extern int EnableMenuItem(IntPtr hMenu, uint wIDEnableItem, uint wEnable);

  public bool IsCableCreatedAction { get; set; }

  public CApFlexCableController CableController { get; set; }

  public CApFLEXCableAttributeViewModel AttributeViewModel { get; set; }

  private CUiFLEXAttachmentFrameWindow AttachmentFrameWindow { get; set; }

  private CApFLEXFrameValidator FrameValidator { get; set; }

  private bool IsEditMode
  {
    get => this.AttributeViewModel != null && this.AttributeViewModel.IsEditMode;
    set
    {
      if (this.AttributeViewModel == null)
        return;
      this.AttributeViewModel.IsEditMode = value;
    }
  }

  private bool IsCableValid { get; set; }

  private bool IsWindowLoading { get; set; }

  private bool IsFrameBeingUpdated { get; set; }

  private bool IsComponentInserting { get; set; }

  private bool IsCableBeingGenerated { get; set; }

  private bool IsCableNameEditorBeingPicked { get; set; }

  private bool IsCableNameEditorBeingFocused { get; set; }

  private bool IsFrameEditorBeingPicked { get; set; }

  private bool ForceOnlyCableNameEditorTextChanging { get; set; }

  private CApFlexParameterController ParameterController { get; set; }

  private CApCableStatusMessageFactory CableStatusMessageFactory { get; set; }

  public ITxCable CableEditorObject
  {
    get => this.m_cableEditorObject;
    set
    {
      if (this.IsCableNameEditorBeingFocused)
        return;
      this.m_cableEditorObject = value;
      if (this.ForceOnlyCableNameEditorTextChanging)
        return;
      this.UpdateCableNameEditor(this.IsCableNameEditorBeingPicked && this.Cable == null && value == null && this.txEditorName.Text == "");
    }
  }

  public ITxCable Cable
  {
    get => this.AttributeViewModel.Cable;
    set
    {
      this.UnregisterCableEvents();
      this.AttributeViewModel.Cable = value;
      this.m_cableEditorObject = this.AttributeViewModel.Cable;
      this.RegisterCableEvents();
    }
  }

  public ITxObject ParentEquipment
  {
    get => this.AttributeViewModel.CableScopeStatus.ParentEquipment;
    set => this.AttributeViewModel.CableScopeStatus.ParentEquipment = value;
  }

  public bool IsCableInEquipment => this.AttributeViewModel.CableScopeStatus.IsCableInEquipment;

  public bool IsCableCreationSucceeded { get; set; }

  public bool HasDefaultDistanceBeenSetUp { get; set; }

  public ITxLocatableObject StartFrame { get; set; }

  public ITxLocatableObject EndFrame { get; set; }

  public ITxLocatableObject PassNearFrame { get; set; }

  public List<ITxLocatableObject> AttachmentFrames { get; set; }

  public CApCableStatusMessageType ErrorMessageStatusBeforeSimulationRunning { get; set; }

  public string ErrorMessageBeforeSimulationRunning { get; set; }

  public CUiFLEXCableEditorWindow(CUiFLEXCreateCableCmd command)
  {
    this.AttachmentFrameWindow = (CUiFLEXAttachmentFrameWindow) null;
    this.IsCableValid = true;
    this.IsFrameBeingUpdated = false;
    this.IsComponentInserting = false;
    this.IsCableNameEditorBeingPicked = false;
    this.HasDefaultDistanceBeenSetUp = false;
    this.IsFrameEditorBeingPicked = false;
    this.CreateDialog(command, true);
    this.IsEditMode = false;
  }

  public CUiFLEXCableEditorWindow(CUiFLEXCreateCableCmd command, ITxComponent equipmentScope)
  {
    this.AttachmentFrameWindow = (CUiFLEXAttachmentFrameWindow) null;
    this.IsCableValid = true;
    this.IsFrameBeingUpdated = false;
    this.IsComponentInserting = false;
    this.IsCableNameEditorBeingPicked = false;
    this.HasDefaultDistanceBeenSetUp = false;
    this.IsFrameEditorBeingPicked = false;
    this.CreateDialog(command, true, parentEquipment: equipmentScope);
    this.IsEditMode = false;
  }

  public CUiFLEXCableEditorWindow(CUiFLEXCreateCableCmd command, ITxCable cable, bool isLicenseOn)
  {
    this.AttachmentFrameWindow = (CUiFLEXAttachmentFrameWindow) null;
    this.IsCableValid = true;
    this.IsFrameBeingUpdated = false;
    this.IsCableNameEditorBeingPicked = false;
    this.HasDefaultDistanceBeenSetUp = true;
    this.IsFrameEditorBeingPicked = false;
    this.CreateDialog(command, isLicenseOn, cable);
    this.ChangeGenerateButtonLabel(CApFLEXStringTable.FlexRegenerateButton);
    this.IsEditMode = true;
  }

  private void TxWindow_Loaded(object sender, RoutedEventArgs e)
  {
    // ISSUE: explicit non-virtual call
    double height = __nonvirtual (((FrameworkElement) this).Height);
    ((FrameworkElement) this).MinHeight = height;
    ((FrameworkElement) this).MaxHeight = height;
    this.InitCableNameEditor();
    this.FrameValidator = new CApFLEXFrameValidator((ICApFLEXFrameSelection) this, this.AttributeViewModel.CableScopeStatus);
    this.InitFrameEditBoxes();
    this.InitCableParameters();
    this.InitExpanders();
    this.AttachmentsUserControl.EndOfLoading();
    if (this.IsEditMode)
    {
      this.FrameValidator.ShowError = false;
      // ISSUE: explicit non-virtual call
      __nonvirtual (((Window) this).Title) = CApFLEXStringTable.CableEditorTitle;
      this.frameBoxCtrlStartFrameCable.Object = (ITxObject) this.AttributeViewModel.StartFrame;
      this.frameBoxCtrlEndFrameCable.Object = (ITxObject) this.AttributeViewModel.EndFrame;
      this.ParametersUserControl.InitFrameEditorBox();
      this.FrameValidator.ShowError = true;
    }
    else
      this.txEditorName.Text = this.AttributeViewModel.CableName;
    this.UpdateStartAttachmentButtonSensitivity();
    this.UpdateEndAttachmentButtonSensitivity();
    this.RegisterActiveDocumentEvent();
    this.RegisterUserControlEvent();
    this.UpdateRegistrationAttachmentFramesNotifications();
    this.UpdateStatusBarMessage();
    this.ParametersUserControl.EndOfLoading();
    this.IsWindowLoading = false;
  }

  private void SimulationPlayer_Started(object sender, TxSimulationPlayer_StartedEventArgs args)
  {
    this.ErrorMessageStatusBeforeSimulationRunning = this.AttributeViewModel.StatusMessageType;
    this.ErrorMessageBeforeSimulationRunning = this.AttributeViewModel.Message;
  }

  private void SimulationPlayer_SimulationStopped(
    object sender,
    TxSimulationPlayer_SimulationStoppedEventArgs args)
  {
    this.UpdateStatusBarMessage();
  }

  private void TxWindow_Closed(object sender, CancelEventArgs e) => this.CloseDialog();

  private void CreateDialog(
    CUiFLEXCreateCableCmd command,
    bool isLicenseOn,
    ITxCable cable = null,
    ITxComponent parentEquipment = null)
  {
    this.AttachmentFrames = new List<ITxLocatableObject>();
    this.IsCableCreatedAction = false;
    this.AttributeViewModel = new CApFLEXCableAttributeViewModel()
    {
      IsLicenseOn = isLicenseOn
    };
    this.InitCableScopeStatus(cable, parentEquipment);
    this.RegisterAttributViewModelPropertyChanged();
    this.RegisterLinearUnitEvent();
    this.ParameterController = new CApFlexParameterController(command);
    this.ParameterController.Load();
    this.CableController = new CApFlexCableController(this.ParameterController, (ICApFLEXCableAttributeViewModel) this.AttributeViewModel);
    this.IsWindowLoading = true;
    this.InitializeComponent();
    this.InitDialog();
    this.IsCableCreationSucceeded = false;
  }

  private void InitCableScopeStatus(ITxCable cable, ITxComponent parentEquipment)
  {
    this.Cable = cable;
    if (parentEquipment != null)
      this.ParentEquipment = (ITxObject) parentEquipment;
    else
      this.ParentEquipment = CApCableUtility.GetParentEquipment((ITxObject) cable);
  }

  private void InitDialogMessage()
  {
    this.AttributeViewModel.CableStatusAnalysis = new CApCableStatusAnalysis((ICApFLEXCableAttributeViewModel) this.AttributeViewModel, this.m_frameAttachmentRetriever);
    this.CableStatusMessageFactory = new CApCableStatusMessageFactory(this.AttributeViewModel.CableStatusAnalysis);
  }

  private void InitCableNameEditor()
  {
    this.txEditorName.SetValidator((ITxValidator) new CApFLEXCableValidator((ICApFLEXCableEditorSelection) this));
    this.txEditorName.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.CableEditBoxCtrl_Picked);
    if (this.Cable == null)
      return;
    this.txEditorName.Text = ((ITxObject) this.Cable).Name;
  }

  private void InitCableParameters()
  {
    if (this.IsEditMode)
      this.CableController.InitViewModelWithCable(this.Cable);
    else
      this.CableController.InitViewModel();
  }

  private void InitDialog()
  {
    // ISSUE: explicit non-virtual call
    __nonvirtual (((Window) this).Title) = CApFLEXStringTable.CableEditorTitle;
    this.AttributeViewModel.IsCloseEnabled = true;
    this.AttributeViewModel.RadiusStepSize = CApCableUtility.ComputeRadiusStepSize();
    this.AttributeViewModel.LengthStepSize = CApCableUtility.ComputeLengthStepSize();
    this.UpdateLinearUnitText();
    this.InitUserControl();
    this.InitDialogMessage();
    // ISSUE: explicit non-virtual call
    ((UIElement) this).KeyUp += new System.Windows.Input.KeyEventHandler(this.m_keyup);
  }

  private void InitExpanders()
  {
    this.AttributeViewModel.IsAttachmentExpanded = this.ParameterController.IsAttachmentsExpanderOpen;
    this.AttributeViewModel.IsParametersExpanded = this.ParameterController.IsParametersExpanderOpen;
  }

  private void InitUserControl()
  {
    this.InitParametersUserControl();
    this.InitAttachmentUserControl();
  }

  private void InitParametersUserControl()
  {
    this.ParametersUserControl.AttributeViewModel = (ICApFLEXCableAttributeViewModel) this.AttributeViewModel;
    this.ParametersUserControl.StartOfLoading();
    this.ParametersUserControl.InitControl();
  }

  private void InitAttachmentUserControl()
  {
    this.AttachmentsUserControl.AttributeViewModel = (ICApFLEXCableAttributeViewModel) this.AttributeViewModel;
    this.AttachmentsUserControl.InitControl(this.m_frameAttachmentRetriever, this.ParameterController);
  }

  private void InitFrameEditBoxes()
  {
    this.frameBoxCtrlStartFrameCable.SetValidator((ITxValidator) this.FrameValidator);
    if (!this.IsEditMode)
    {
      this.frameBoxCtrlStartFrameCable.Focus();
      this.AttributeViewModel.FocusedPickableControl = PickableControlFocusStatus.StartFrame;
    }
    this.frameBoxCtrlEndFrameCable.SetValidator((ITxValidator) this.FrameValidator);
    this.ParametersUserControl.FrameValidator = this.FrameValidator;
    this.ParametersUserControl.InitFrameEditorBox();
    this.AttachmentsUserControl.FrameValidator = this.FrameValidator;
    this.RegisterFrameEditorEvent();
  }

  private void RegisterCableEvents()
  {
    if (this.Cable == null)
      return;
    this.UnregisterCableEvents();
    if (this.Cable is ITxComponent cable)
    {
      cable.ModelingStateChanged += new TxComponent_ModelingStateChangedEventHandler(this.Cable_ModelingStateChanged);
      cable.Reloaded += new TxComponent_ReloadedEventHandler(this.Cable_Reload);
      ((ITxObject) this.Cable).NameChanged += new TxObject_NameChangedEventHandler(this.Cable_NameChanged);
      ((ITxObject) this.Cable).Deleted += new TxObject_DeletedEventHandler(this.Cable_Deleted);
      this.Cable.Modified += new TxCable_ModifiedEventHandler(this.Cable_Modified);
    }
    this.RegisterEquipmentEvents();
  }

  private void RegisterEquipmentEvents()
  {
    if (!this.IsCableInEquipment || !(this.ParentEquipment is ITxComponent parentEquipment))
      return;
    parentEquipment.ModelingStateChanged += new TxComponent_ModelingStateChangedEventHandler(this.CableEquipment_ModelingStateChanged);
  }

  private void UnRegisterEquipmentEvents()
  {
    if (!this.IsCableInEquipment || !(this.ParentEquipment is ITxComponent parentEquipment))
      return;
    parentEquipment.ModelingStateChanged -= new TxComponent_ModelingStateChangedEventHandler(this.CableEquipment_ModelingStateChanged);
  }

  private void RemoveAttachmentsFromGrid()
  {
    this.AttachmentsUserControl.AttributeViewModel.AttachmentDataList = new List<CApFLEXAttachment>();
    this.AttachmentsUserControl.UpdateAddRemoveAttachmentSensitivity();
    this.AttachmentsUserControl.UpdateAttachmentFlexGrid();
  }

  private void UnregisterCableEvents()
  {
    if (this.Cable == null)
      return;
    if (this.Cable is ITxComponent cable)
    {
      cable.ModelingStateChanged -= new TxComponent_ModelingStateChangedEventHandler(this.Cable_ModelingStateChanged);
      cable.Reloaded -= new TxComponent_ReloadedEventHandler(this.Cable_Reload);
      ((ITxObject) this.Cable).NameChanged -= new TxObject_NameChangedEventHandler(this.Cable_NameChanged);
      ((ITxObject) this.Cable).Deleted -= new TxObject_DeletedEventHandler(this.Cable_Deleted);
      this.Cable.Modified -= new TxCable_ModifiedEventHandler(this.Cable_Modified);
    }
    this.UnRegisterEquipmentEvents();
  }

  private void RegisterUserControlEvent()
  {
    this.AttachmentsUserControl.AttachmentDialogOpened += new CApCableEventHandler(this.AttachmentDialog_OpenedHandler);
    this.AttachmentsUserControl.AttachmentDialogClosed += new CApCableEventHandler(this.AttachmentDialog_ClosedHandler);
    this.ParametersUserControl.TentativePropertyChanged += new TentativePropertyChangedEventHandler(this.ParameterUserControl_TentativePropertyChanged);
  }

  private void UnregisterUserControlEvent()
  {
    this.AttachmentsUserControl.AttachmentDialogOpened -= new CApCableEventHandler(this.AttachmentDialog_OpenedHandler);
    this.AttachmentsUserControl.AttachmentDialogClosed -= new CApCableEventHandler(this.AttachmentDialog_ClosedHandler);
    this.ParametersUserControl.TentativePropertyChanged -= new TentativePropertyChangedEventHandler(this.ParameterUserControl_TentativePropertyChanged);
  }

  private void RegisterActiveDocumentEvent()
  {
    TxApplication.ActiveDocument.SimulationPlayer.SimulationStopped += new TxSimulationPlayer_SimulationStoppedEventHandler(this.SimulationPlayer_SimulationStopped);
    TxApplication.ActiveDocument.SimulationPlayer.Started += new TxSimulationPlayer_StartedEventHandler(this.SimulationPlayer_Started);
    TxApplication.ActiveDocument.Unloading += new TxDocument_UnloadingEventHandler(this.ActiveDocument_Unloading);
    TxApplication.ActiveDocument.PhysicalRoot.ItemCreated += new TxObjectRoot_ItemCreatedEventHandler(this.Cable_OnInsertComponent);
  }

  private void UnregisterActiveDocumentEvent()
  {
    TxApplication.ActiveDocument.SimulationPlayer.SimulationStopped -= new TxSimulationPlayer_SimulationStoppedEventHandler(this.SimulationPlayer_SimulationStopped);
    TxApplication.ActiveDocument.SimulationPlayer.Started -= new TxSimulationPlayer_StartedEventHandler(this.SimulationPlayer_Started);
    TxApplication.ActiveDocument.Unloading -= new TxDocument_UnloadingEventHandler(this.ActiveDocument_Unloading);
    TxApplication.ActiveDocument.PhysicalRoot.ItemCreated -= new TxObjectRoot_ItemCreatedEventHandler(this.Cable_OnInsertComponent);
  }

  private void RegisterFrameEditorEvent()
  {
    this.frameBoxCtrlStartFrameCable.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.FrameEditBoxCtrlStart_Picked);
    this.frameBoxCtrlEndFrameCable.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.FrameEditBoxCtrlEnd_Picked);
    ((UIElement) this.frameBoxCtrlStartFrameCable).KeyUp += new System.Windows.Input.KeyEventHandler(this.FrameBoxCable_KeyUp);
    ((UIElement) this.frameBoxCtrlEndFrameCable).KeyUp += new System.Windows.Input.KeyEventHandler(this.FrameBoxCable_KeyUp);
  }

  private void UnregisterFrameEditorEvent()
  {
    this.frameBoxCtrlStartFrameCable.Picked -= new TxObjEditBoxCtrl_PickedEventHandler(this.FrameEditBoxCtrlStart_Picked);
    this.frameBoxCtrlEndFrameCable.Picked -= new TxObjEditBoxCtrl_PickedEventHandler(this.FrameEditBoxCtrlEnd_Picked);
    ((UIElement) this.frameBoxCtrlStartFrameCable).KeyUp -= new System.Windows.Input.KeyEventHandler(this.FrameBoxCable_KeyUp);
    ((UIElement) this.frameBoxCtrlEndFrameCable).KeyUp -= new System.Windows.Input.KeyEventHandler(this.FrameBoxCable_KeyUp);
  }

  private void RegisterLinearUnitEvent()
  {
    TxApplication.Options.Units.LinearUnitsChanged += new TxUnitsOptions_LinearUnitsChangedEventHandler(this.Units_LinearUnitsChanged);
  }

  private void UnregisterLinearUnitEvent()
  {
    TxApplication.Options.Units.LinearUnitsChanged -= new TxUnitsOptions_LinearUnitsChangedEventHandler(this.Units_LinearUnitsChanged);
  }

  private void RegisterAttributViewModelPropertyChanged()
  {
    this.AttributeViewModel.PropertyChanged += new PropertyChangedEventHandler(this.AttributeViewModel_PropertyChanged);
    this.AttributeViewModel.PropertyWillChange += new PropertyChangedEventHandler(this.AttributeViewModel_PropertyWillChange);
  }

  private void UnregisterAttributViewModelPropertyChanged()
  {
    this.AttributeViewModel.PropertyChanged -= new PropertyChangedEventHandler(this.AttributeViewModel_PropertyChanged);
    this.AttributeViewModel.PropertyWillChange -= new PropertyChangedEventHandler(this.AttributeViewModel_PropertyWillChange);
  }

  private void UnregisterAttachmentFrameNotifications()
  {
    this.UnregisterAttachmentFrameNotifications(this.StartFrame);
    this.UnregisterAttachmentFrameNotifications(this.EndFrame);
    this.UnregisterAttachmentAttachmentFrameNotifications();
    this.UnregisterAttachmentFrameNotifications(this.PassNearFrame);
  }

  private void UnregisterAttachmentFrameNotifications(ITxLocatableObject frame)
  {
    if (frame == null)
      return;
    if (frame != this.PassNearFrame)
    {
      ((ITxObject) frame).NameChanged -= new TxObject_NameChangedEventHandler(this.Frame_NameChanged);
      ((ITxObject) frame).Deleted -= new TxObject_DeletedEventHandler(this.Frame_Deleted);
    }
    frame.AbsoluteLocationChanged -= new TxLocatableObject_AbsoluteLocationChangedEventHandler(this.Frame_AbsoluteLocationChanged);
    frame.AttachmentParentChanged -= new TxLocatableObject_AttachmentParentChangedEventHandler(this.Frame_AttachmentParentChanged);
  }

  private void RegisterAttachmentFrameNotifications(ITxLocatableObject frame, bool isPassNearFrame)
  {
    if (frame == null)
      return;
    if (!isPassNearFrame)
    {
      frame.AbsoluteLocationChanged += new TxLocatableObject_AbsoluteLocationChangedEventHandler(this.Frame_AbsoluteLocationChanged);
      ((ITxObject) frame).NameChanged += new TxObject_NameChangedEventHandler(this.Frame_NameChanged);
    }
    ((ITxObject) frame).Deleted += new TxObject_DeletedEventHandler(this.Frame_Deleted);
    frame.AttachmentParentChanged += new TxLocatableObject_AttachmentParentChangedEventHandler(this.Frame_AttachmentParentChanged);
  }

  private void RegisterAttachmentAttachmentFrameNotifications()
  {
    foreach (ITxLocatableObject attachmentFrame in this.AttachmentFrames)
    {
      if (attachmentFrame != null)
      {
        attachmentFrame.AbsoluteLocationChanged += new TxLocatableObject_AbsoluteLocationChangedEventHandler(this.Frame_AbsoluteLocationChanged);
        attachmentFrame.AttachmentParentChanged += new TxLocatableObject_AttachmentParentChangedEventHandler(this.Frame_AttachmentParentChanged);
      }
    }
  }

  private void UnregisterAttachmentAttachmentFrameNotifications()
  {
    foreach (ITxLocatableObject attachmentFrame in this.AttachmentFrames)
    {
      if (attachmentFrame != null)
      {
        attachmentFrame.AbsoluteLocationChanged -= new TxLocatableObject_AbsoluteLocationChangedEventHandler(this.Frame_AbsoluteLocationChanged);
        attachmentFrame.AttachmentParentChanged -= new TxLocatableObject_AttachmentParentChangedEventHandler(this.Frame_AttachmentParentChanged);
      }
    }
  }

  private void RegisterAttachmentFramesNotifications()
  {
    this.RegisterAttachmentFrameNotifications(this.StartFrame, false);
    this.RegisterAttachmentFrameNotifications(this.EndFrame, false);
    this.RegisterAttachmentAttachmentFrameNotifications();
    this.RegisterAttachmentFrameNotifications(this.PassNearFrame, true);
  }

  private void EndFrame_LostFocus(object sender, RoutedEventArgs e)
  {
    CApCableUtility.UnHighlightObject((ITxDisplayableObject) (this.AttributeViewModel.EndFrame as TxFrame));
    this.AttachmentsUserControl.UpdateAddRemoveAttachmentSensitivity();
    this.AttributeViewModel.FocusedPickableControl = PickableControlFocusStatus.None;
  }

  private void StartFrame_LostFocus(object sender, RoutedEventArgs e)
  {
    CApCableUtility.UnHighlightObject((ITxDisplayableObject) (this.AttributeViewModel.StartFrame as TxFrame));
    this.AttachmentsUserControl.UpdateAddRemoveAttachmentSensitivity();
    this.AttributeViewModel.FocusedPickableControl = PickableControlFocusStatus.None;
  }

  private void StartFrame_GotFocus(object sender, RoutedEventArgs e)
  {
    if (this.frameBoxCtrlStartFrameCable.Text != "")
      CApCableUtility.HighlightObject((ITxDisplayableObject) (this.AttributeViewModel.StartFrame as TxFrame));
    this.AttributeViewModel.FocusedPickableControl = PickableControlFocusStatus.StartFrame;
  }

  private void EndFrame_GotFocus(object sender, RoutedEventArgs e)
  {
    if (this.frameBoxCtrlEndFrameCable.Text != "")
      CApCableUtility.HighlightObject((ITxDisplayableObject) (this.AttributeViewModel.EndFrame as TxFrame));
    this.AttributeViewModel.FocusedPickableControl = PickableControlFocusStatus.EndFrame;
  }

  private void FrameEditBoxCtrlEnd_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    this.IsFrameEditorBeingPicked = true;
    TxFrame frame2 = args.Object as TxFrame;
    this.UnHighlightObjects();
    if (TxFrame.op_Inequality(frame2, (ITxObject) null))
    {
      if (args.IsValidObjectPicked)
      {
        this.AttributeViewModel.EndFrame = (ITxLocatableObject) frame2;
        this.AttributeViewModel.EndAttachPartTo = (ITxObject) TxEngineeringDataInternal.GetAttachmentScope((ITxLocatableObject) frame2);
        CApCableUtility.HighlightObject((ITxDisplayableObject) frame2);
        this.UpdateEndLocatedAttachmentFrame();
        double distance;
        if (this.AttributeViewModel.StartFrame != null && !this.IsEditMode && !this.HasDefaultDistanceBeenSetUp && CApCableUtility.ComputeDistanceBetweenFrames(this.AttributeViewModel.StartFrame, (ITxLocatableObject) frame2, out distance))
        {
          double num = CApCableUtility.ComputeLinearRoundValueWithCurrentUnit(distance) * TxApplication.Options.Units.LinearMultiplier;
          this.HasDefaultDistanceBeenSetUp = true;
          if (this.AttributeViewModel.Length < num)
            this.AttributeViewModel.Length = num;
        }
      }
      else
        this.AttributeViewModel.EndFrame = (ITxLocatableObject) null;
    }
    else
      this.AttributeViewModel.EndFrame = (ITxLocatableObject) null;
    this.IsFrameEditorBeingPicked = false;
  }

  private void FrameEditBoxCtrlStart_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    this.IsFrameEditorBeingPicked = true;
    TxFrame frame1 = args.Object as TxFrame;
    CApCableUtility.UnHighlightObject((ITxDisplayableObject) (this.AttributeViewModel.StartFrame as TxFrame));
    if (TxFrame.op_Inequality(frame1, (ITxObject) null))
    {
      if (args.IsValidObjectPicked)
      {
        this.AttributeViewModel.StartFrame = (ITxLocatableObject) frame1;
        this.AttributeViewModel.StartAttachPartTo = (ITxObject) TxEngineeringDataInternal.GetAttachmentScope((ITxLocatableObject) frame1);
        CApCableUtility.HighlightObject((ITxDisplayableObject) frame1);
        this.UpdateStartLocatedAttachmentFrame();
      }
      else
        this.AttributeViewModel.StartFrame = (ITxLocatableObject) null;
      if (this.frameBoxCtrlEndFrameCable.Text == "")
      {
        this.SetFrameFocus(FrameSelectionType.EndFrame);
      }
      else
      {
        double distance;
        if (this.AttributeViewModel.EndFrame != null && !this.IsEditMode && !this.HasDefaultDistanceBeenSetUp && CApCableUtility.ComputeDistanceBetweenFrames((ITxLocatableObject) frame1, this.AttributeViewModel.EndFrame, out distance))
        {
          double num = CApCableUtility.ComputeLinearRoundValueWithCurrentUnit(distance) * TxApplication.Options.Units.LinearMultiplier;
          this.HasDefaultDistanceBeenSetUp = true;
          if (this.AttributeViewModel.Length < num)
            this.AttributeViewModel.Length = num;
        }
      }
    }
    this.IsFrameEditorBeingPicked = false;
  }

  private void CableEditBoxCtrl_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    this.IsCableNameEditorBeingPicked = true;
    TxCable cable = args.Object as TxCable;
    if (TxCable.op_Inequality(cable, (ITxObject) null))
    {
      if (this.Cable == null || this.Cable != cable)
      {
        this.ForceOnlyCableNameEditorTextChanging = true;
        string text = this.txEditorName.Text;
        this.txEditorName.Text = this.AttributeViewModel.CableName;
        bool flag = true;
        if (this.Cable == null || this.Cable != null && this.HasCableDialogParametersChanged(this.Cable.CableData))
          flag = TxMessageBox.ShowModal(string.Format(CApFLEXStringTable.EDIT_CABLE_UPDATE_WARNING, (object) this.AttributeViewModel.CableName), CApFLEXStringTable.EDIT_CABLE_UPDATE_TITLE, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK;
        if (flag)
        {
          ITxComponent itxComponent = (ITxComponent) cable;
          if (itxComponent != null)
            this.AttributeViewModel.IsCableEditable = itxComponent.IsOpenForModeling;
          this.AttributeViewModel.CableName = text;
          this.ForceOnlyCableNameEditorTextChanging = false;
          this.UpdateCableNameEditor(true);
          this.UpdateCableDialog((ITxCable) cable);
        }
        else
          this.UpdateCableNameEditor(true);
      }
    }
    else if (this.Cable != null)
    {
      this.txEditorName.Object = (ITxObject) this.Cable;
      this.txEditorName.Text = ((ITxObject) this.Cable).Name;
    }
    else
      this.UpdateCableNameEditor(true);
    this.IsCableNameEditorBeingPicked = false;
  }

  private void SetFrameFocus(FrameSelectionType frameType)
  {
    switch (frameType)
    {
      case FrameSelectionType.StartFrame:
        this.frameBoxCtrlStartFrameCable.Focus();
        this.AttributeViewModel.FocusedPickableControl = PickableControlFocusStatus.StartFrame;
        break;
      case FrameSelectionType.EndFrame:
        this.frameBoxCtrlEndFrameCable.Focus();
        this.AttributeViewModel.FocusedPickableControl = PickableControlFocusStatus.EndFrame;
        break;
    }
  }

  private void AttachmentDialog_OpenedHandler() => ((UIElement) this).IsEnabled = false;

  private void AttachmentDialog_ClosedHandler() => ((UIElement) this).IsEnabled = true;

  private void AttributeViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
  {
    if (this.IsComponentInserting || this.IsWindowLoading)
      return;
    if (this.AttributeViewModel.IsCreationParameter(e.PropertyName))
    {
      this.ParameterChanged();
      if (e.PropertyName == "Length")
      {
        this.AttributeViewModel.UpdateMaxRetractedLength();
        this.AttributeViewModel.UpdateEndAttachmentLengthFromStart();
      }
    }
    if (!this.AttributeViewModel.IsFrameParameter(e.PropertyName))
      return;
    switch (e.PropertyName)
    {
      case "StartFrame":
      case "StartAttachPartTo":
        this.UpdateAttachmentFrameRegistry(this.StartFrame, this.AttributeViewModel.StartAttachPartTo);
        this.UpdateStartAttachmentButtonSensitivity();
        break;
      case "EndFrame":
      case "EndAttachPartTo":
        this.UpdateAttachmentFrameRegistry(this.EndFrame, this.AttributeViewModel.EndAttachPartTo);
        this.UpdateEndAttachmentButtonSensitivity();
        break;
      case "PassNearFrame":
        this.UpdateAttachmentFrameRegistry(this.PassNearFrame);
        break;
    }
    this.ParameterChanged();
    if (!(e.PropertyName == "StartFrame") && !(e.PropertyName == "EndFrame") && !(e.PropertyName == "PassNearFrame"))
      return;
    this.UpdateRegistrationAttachmentFramesNotifications();
  }

  private void AttributeViewModel_PropertyWillChange(object sender, PropertyChangedEventArgs e)
  {
    if (!this.AttributeViewModel.IsFrameParameter(e.PropertyName))
      return;
    switch (e.PropertyName)
    {
      case "StartFrame":
        this.UpdateAttachmentFrameRegistry(this.StartFrame, this.AttributeViewModel.StartAttachPartTo);
        break;
      case "EndFrame":
        this.UpdateAttachmentFrameRegistry(this.EndFrame, this.AttributeViewModel.EndAttachPartTo);
        break;
      case "PassNearFrame":
        this.UpdateAttachmentFrameRegistry(this.PassNearFrame);
        break;
    }
  }

  private void ParameterUserControl_TentativePropertyChanged(object sender)
  {
    this.ParameterChanged();
    if (!this.AttributeViewModel.IsGenerateEnabled || this.AttributeViewModel.Density <= 1000000.0 && this.AttributeViewModel.Density >= 0.01 && this.AttributeViewModel.YoungsModulus <= 1000.0 && this.AttributeViewModel.YoungsModulus >= 0.1 && this.AttributeViewModel.MaxTension <= 9810.0 && this.AttributeViewModel.MaxTension >= 0.0 && this.AttributeViewModel.MaxTwistAngle <= 20.0 * Math.PI && this.AttributeViewModel.MaxTwistAngle >= 0.0 && this.AttributeViewModel.MaxContactForce <= 9810.0 && this.AttributeViewModel.MaxContactForce >= 0.0 && this.AttributeViewModel.MinCurvatureRadius <= 10000.0 && this.AttributeViewModel.MinCurvatureRadius >= 0.0)
      return;
    this.DisableGenerateButton();
  }

  private void Expander_SizeChanged(object sender, SizeChangedEventArgs e)
  {
    if (this.IsWindowLoading)
      return;
    // ISSUE: explicit non-virtual call
    double num = __nonvirtual (((FrameworkElement) this).Height) + (e.NewSize.Height - e.PreviousSize.Height);
    ((FrameworkElement) this).MinHeight = num;
    ((FrameworkElement) this).MaxHeight = num;
  }

  private void Cable_Reload(object sender, TxComponent_ReloadedEventArgs args)
  {
    if (!(sender is ITxComponent itxComponent))
      return;
    this.AttributeViewModel.IsCableEditable = itxComponent.IsOpenForModeling;
    this.UpdateCableDialog();
  }

  private void Cable_NameChanged(object sender, TxObject_NameChangedEventArgs args)
  {
    if (sender == null)
      return;
    ITxCable cable = this.Cable;
    if (cable == null)
      return;
    this.AttributeViewModel.CableName = ((ITxObject) cable).Name;
    this.UpdateCableNameEditor(true);
  }

  private void Cable_ModelingStateChanged(
    object sender,
    TxComponent_ModelingStateChangedEventArgs args)
  {
    if (sender == null || !(this.Cable is ITxComponent cable))
      return;
    this.AttributeViewModel.IsCableEditable = cable.IsOpenForModeling;
  }

  private void CableEquipment_ModelingStateChanged(
    object sender,
    TxComponent_ModelingStateChangedEventArgs args)
  {
    if (sender == null || this.AttributeViewModel.CableScopeStatus.ParentEquipment == null || !(this.ParentEquipment is ITxComponent parentEquipment))
      return;
    this.AttributeViewModel.IsEquipmentEditable = parentEquipment.IsOpenForModeling;
  }

  private void Cable_Modified(object sender, TxCable_ModifiedEventArgs args)
  {
    if (this.IsCableBeingGenerated || this.Cable == null)
      return;
    this.UpdateCableDialog();
    this.ParameterChanged();
  }

  private void Cable_Deleted(object sender, TxObject_DeletedEventArgs args)
  {
    if (sender == null || sender as ITxCable != this.Cable)
      return;
    this.RemoveAttachmentsFromGrid();
    this.UnregisterCableEvents();
    this.SwitchToCreateMode();
    this.ParameterChanged();
    this.IsCableCreatedAction = false;
    this.Cable = (ITxCable) null;
  }

  private void Cable_OnInsertComponent(object sender, TxObjectRoot_ItemCreatedEventArgs args)
  {
    if (this.Cable == null)
      return;
    this.IsComponentInserting = true;
    if (args.Item is ITxCable itxCable)
    {
      if (((ITxObject) itxCable).Id == ((ITxObject) this.Cable).Id)
      {
        if (!this.IsCableCreatedAction)
        {
          this.UpdateCableDialog();
          this.RegisterCableEvents();
        }
        this.IsCableCreatedAction = false;
      }
    }
    else
    {
      TxFrame txFrame = args.Item as TxFrame;
      if (TxFrame.op_Inequality(txFrame, (ITxObject) null))
      {
        TxCableData cableData = this.Cable.CableData;
        if (cableData != null)
        {
          if (cableData.PassNearFrame != null)
          {
            if (((ITxObject) cableData.PassNearFrame).Id == txFrame.Id)
              this.UpdateCableDialog();
          }
          else
          {
            bool flag = false;
            for (int index = 0; !flag && index < cableData.Attachments.Count; ++index)
            {
              if (((ITxObject) TxFlxCableEx.GetAttachmentFrame(this.Cable, index)).Id == txFrame.Id)
              {
                this.UpdateCableDialog();
                flag = true;
              }
            }
          }
        }
      }
    }
    this.IsComponentInserting = false;
  }

  private void Frame_Deleted(object sender, TxObject_DeletedEventArgs args)
  {
    bool flag = false;
    if (!(sender is ITxLocatableObject itxLocatableObject))
      return;
    if (itxLocatableObject == this.AttributeViewModel.StartFrame)
    {
      this.AttributeViewModel.StartFrame = (ITxLocatableObject) null;
      this.AttributeViewModel.StartAttachPartTo = (ITxObject) null;
      this.frameBoxCtrlStartFrameCable.Object = (ITxObject) null;
      this.frameBoxCtrlStartFrameCable.Text = "";
      flag = true;
    }
    else if (itxLocatableObject == this.AttributeViewModel.EndFrame)
    {
      this.frameBoxCtrlEndFrameCable.Text = "";
      this.AttributeViewModel.EndFrame = (ITxLocatableObject) null;
      this.AttributeViewModel.EndAttachPartTo = (ITxObject) null;
      this.frameBoxCtrlEndFrameCable.Object = (ITxObject) null;
      flag = true;
    }
    if (!flag)
      return;
    this.ParameterChanged();
  }

  private void Frame_AttachmentParentChanged(
    object sender,
    TxLocatableObject_AttachmentParentChangedEventArgs args)
  {
    if (sender == null)
      return;
    TxFrame txFrame = sender as TxFrame;
    if (!TxFrame.op_Inequality(txFrame, (ITxObject) null))
      return;
    ITxObject attachmentScope = (ITxObject) TxEngineeringDataInternal.GetAttachmentScope(sender as ITxLocatableObject);
    if (TxFrame.op_Equality(txFrame, (ITxObject) this.StartFrame))
      this.AttributeViewModel.StartAttachPartTo = attachmentScope;
    else if (TxFrame.op_Equality(txFrame, (ITxObject) this.EndFrame))
      this.AttributeViewModel.EndAttachPartTo = attachmentScope;
    this.UpdateAttachmentFrameRegistry(sender as ITxLocatableObject, attachmentScope);
    this.ParameterChanged();
  }

  private void Frame_NameChanged(object sender, TxObject_NameChangedEventArgs args)
  {
    this.IsFrameBeingUpdated = true;
    if (sender is ITxLocatableObject itxLocatableObject)
    {
      if (itxLocatableObject == this.AttributeViewModel.StartFrame)
        this.frameBoxCtrlStartFrameCable.Text = ((ITxObject) itxLocatableObject).Name;
      else if (itxLocatableObject == this.AttributeViewModel.EndFrame)
        this.frameBoxCtrlEndFrameCable.Text = ((ITxObject) itxLocatableObject).Name;
    }
    this.ParameterChanged();
    this.IsFrameBeingUpdated = false;
  }

  private void Frame_AbsoluteLocationChanged(
    object sender,
    TxLocatableObject_AbsoluteLocationChangedEventArgs args)
  {
    if (!this.IsFrameBeingUpdated)
    {
      if (this.AttributeViewModel.StartFrame == null || this.AttributeViewModel.EndFrame == null)
        return;
      this.IsFrameBeingUpdated = true;
      if (!this.AttributeViewModel.IsGenerateEnabled && !TxApplication.ActiveDocument.SimulationPlayer.IsSimulationRunning())
        this.EnableGenerateButton();
      this.ParameterChanged();
    }
    else
      this.IsFrameBeingUpdated = false;
  }

  private void ActiveDocument_Unloading(object sender, TxDocument_UnloadingEventArgs args)
  {
    ((Window) this).Close();
  }

  private void statusbar_SizeChanged(object sender, SizeChangedEventArgs e)
  {
    if (this.IsWindowLoading)
      return;
    // ISSUE: explicit non-virtual call
    double num = __nonvirtual (((FrameworkElement) this).Height) + (e.NewSize.Height - e.PreviousSize.Height);
    ((FrameworkElement) this).MinHeight = num;
    ((FrameworkElement) this).MaxHeight = num;
  }

  private void Units_LinearUnitsChanged(
    object sender,
    TxUnitsOptions_LinearUnitsChangedEventArgs args)
  {
    this.UpdateLinearUnitText();
    ((UIElement) this.TxNumericEditBoxLength).Refresh();
  }

  private void btnGenerate_Click(object sender, RoutedEventArgs e)
  {
    this.IsCableBeingGenerated = true;
    this.UpdateRetractSystemCurrentMaxRetractedLength();
    if (this.CreateOrUpdateCable(CUiFLEXCableEditorWindow.UpdateCableOption.FORCE_UPDATE))
    {
      if (!this.IsEditMode)
      {
        this.SwitchToEditMode();
      }
      else
      {
        this.IsCableValid = true;
        this.DisableGenerateButton();
      }
    }
    this.IsCableBeingGenerated = false;
  }

  private void btnClose_Click(object sender, RoutedEventArgs e) => ((Window) this).Close();

  private void FrameBoxCable_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
  {
    if (e.Key != Key.Back && e.Key != Key.Delete)
      return;
    if (sender == this.frameBoxCtrlStartFrameCable)
    {
      CApCableUtility.UnHighlightObject(this.AttributeViewModel.StartFrame as ITxDisplayableObject);
      this.AttributeViewModel.StartFrame = (ITxLocatableObject) null;
      this.AttributeViewModel.StartAttachPartTo = (ITxObject) null;
      this.frameBoxCtrlStartFrameCable.Text = string.Empty;
    }
    else
    {
      if (sender != this.frameBoxCtrlEndFrameCable)
        return;
      CApCableUtility.UnHighlightObject(this.AttributeViewModel.EndFrame as ITxDisplayableObject);
      this.AttributeViewModel.EndFrame = (ITxLocatableObject) null;
      this.AttributeViewModel.EndAttachPartTo = (ITxObject) null;
      this.frameBoxCtrlEndFrameCable.Text = string.Empty;
    }
  }

  private void m_keyup(object sender, System.Windows.Input.KeyEventArgs e)
  {
    if (e.Key != Key.Escape)
      return;
    ((Window) this).Close();
  }

  private void TxNumericEditBox_GotFocus(object send, RoutedEventArgs e)
  {
  }

  private void TxNumericEditBoxLength_TentativeValueChanged(
    object sender,
    TxNumericEditBoxCtrl_TentativeValueChangedEventArgs args)
  {
    if (this.IsFrameEditorBeingPicked || this.IsWindowLoading)
      return;
    this.AttributeViewModel.SetLengthNoEventSent(args.TentativeValue * TxApplication.Options.Units.LinearMultiplier);
    this.ParameterChanged();
    if (!this.AttributeViewModel.IsGenerateEnabled || this.AttributeViewModel.Length <= 30000.0 && this.AttributeViewModel.Length >= 0.01)
      return;
    this.DisableGenerateButton();
  }

  private void TxNumericEditBoxRadius_TentativeValueChanged(
    object sender,
    TxNumericEditBoxCtrl_TentativeValueChangedEventArgs args)
  {
    this.AttributeViewModel.SetRadiusNoEventSent(args.TentativeValue * TxApplication.Options.Units.LinearMultiplier);
    this.ParameterChanged();
    if (!this.AttributeViewModel.IsGenerateEnabled || this.AttributeViewModel.Radius <= 500.0 && this.AttributeViewModel.Radius >= 1.0)
      return;
    this.DisableGenerateButton();
  }

  public bool ShouldDisplayCableEditorEmptyToolTip()
  {
    bool flag = false;
    if (!this.IsCableNameEditorBeingPicked && !this.IsWindowLoading)
      flag = true;
    return flag;
  }

  public bool IsAttachmentFrameFocused()
  {
    return ((UIElement) this.frameBoxCtrlStartFrameCable).IsFocused || ((UIElement) this.frameBoxCtrlEndFrameCable).IsFocused || ((UIElement) this.ParametersUserControl.frameBoxCtrlPassNearFrameCable).IsFocused;
  }

  public bool IsAttachmentFrameAvailableForCheck()
  {
    bool flag = !this.AttachmentsUserControl.IsAttachmentDialogLaunching;
    if (flag && this.AttachmentsUserControl.NewAttachmentWindow != null)
      flag = !((FrameworkElement) this.AttachmentsUserControl.NewAttachmentWindow).IsLoaded;
    return flag;
  }

  public bool IsFrameScopeValid(ITxLocatableObject locatableObject)
  {
    bool flag = true;
    if (this.IsCableInEquipment && this.AttributeViewModel.IsFrameCtrlPassNearFocused && !CApCableUtility.IsObjectInsideEquipment((ITxObject) locatableObject, this.ParentEquipment))
      flag = false;
    return flag;
  }

  public bool IsFrameAlreadyUsed(
    ITxLocatableObject locatableObject,
    out FrameSelectionType frameSelectionType)
  {
    bool flag = false;
    frameSelectionType = FrameSelectionType.None;
    if (!this.IsFrameBeingUpdated && !this.IsCableBeingGenerated && this.IsAttachmentFrameAvailableForCheck())
    {
      if (locatableObject != null && !this.IsComponentInserting)
      {
        Color.FromArgb((int) byte.MaxValue, 0, (int) byte.MaxValue, 0);
        if (this.AttributeViewModel.StartFrame == locatableObject && !this.AttributeViewModel.IsFrameCtrlStartFocused)
        {
          if (this.Cable != null && this.Cable.StartFrame == locatableObject)
          {
            frameSelectionType = FrameSelectionType.StartFrame;
            flag = true;
          }
          else if (this.AttributeViewModel.IsFrameCtrlEndFocused || this.AttributeViewModel.IsFrameCtrlPassNearFocused)
          {
            frameSelectionType = FrameSelectionType.StartFrame;
            flag = true;
          }
        }
        else if (this.AttributeViewModel.EndFrame == locatableObject && !this.AttributeViewModel.IsFrameCtrlEndFocused)
        {
          if (this.Cable != null && this.Cable.EndFrame == locatableObject)
          {
            frameSelectionType = FrameSelectionType.EndFrame;
            flag = true;
          }
          else if (this.AttributeViewModel.IsFrameCtrlStartFocused || this.AttributeViewModel.IsFrameCtrlPassNearFocused)
          {
            frameSelectionType = FrameSelectionType.EndFrame;
            flag = true;
          }
        }
        else if (this.AttributeViewModel.PassNearFrame == locatableObject && !this.AttributeViewModel.IsFrameCtrlPassNearFocused)
        {
          frameSelectionType = FrameSelectionType.PassNearFrame;
          flag = true;
          if (this.AttributeViewModel.IsFrameCtrlStartFocused || this.AttributeViewModel.IsFrameCtrlEndFocused)
          {
            frameSelectionType = FrameSelectionType.PassNearFrame;
            flag = true;
          }
        }
        else
        {
          List<CApFLEXAttachment>.Enumerator enumerator = this.AttributeViewModel.RawAttachmentList().GetEnumerator();
          while (!flag && enumerator.MoveNext())
            flag = this.IsFrameAlreadyUsedAsAttachmentFrame(locatableObject, enumerator.Current);
          if (flag)
            frameSelectionType = FrameSelectionType.AttachmentFrame;
        }
      }
    }
    else
      flag = false;
    return flag;
  }

  private bool IsFrameAlreadyUsedAsAttachmentFrame(
    ITxLocatableObject frame,
    CApFLEXAttachment attachment)
  {
    bool flag = attachment.Location == CApFLEXAttachmentLocation.AlongCable;
    if (flag)
    {
      flag = attachment.FixedFrame == frame;
      if (!flag && attachment is CApFLEXRetractSystemAttachmentType3 systemAttachmentType3)
        flag = systemAttachmentType3.SecondaryFixedFrame == frame;
    }
    return flag;
  }

  private void ParameterChanged()
  {
    if (this.IsWindowLoading)
      return;
    this.UpdateStatusBarMessage();
  }

  private void UpdateCableNameEditor(bool restorePreviousName)
  {
    if (restorePreviousName && this.txEditorName.Text != this.AttributeViewModel.CableName)
      this.txEditorName.Text = this.AttributeViewModel.CableName;
    else
      this.AttributeViewModel.CableName = this.txEditorName.Text;
  }

  public void UpdateStartLocatedAttachmentFrame()
  {
    this.AttributeViewModel.ChangeStartLocatedAttachmentFrame();
  }

  public void UpdateEndLocatedAttachmentFrame()
  {
    this.AttributeViewModel.ChangeEndLocatedAttachmentFrame();
  }

  public void UpdateRetractSystemCurrentMaxRetractedLength()
  {
    this.AttributeViewModel.UpdateRetractSystemCurrentMaxRetractedLength();
  }

  private void UpdateStartAttachmentButtonSensitivity()
  {
    if (this.AttributeViewModel.StartFrame == null)
      this.AttributeViewModel.IsEditStartAttachmentFrameEnabled = false;
    else
      this.AttributeViewModel.IsEditStartAttachmentFrameEnabled = true;
  }

  private void UpdateEndAttachmentButtonSensitivity()
  {
    if (this.AttributeViewModel.EndFrame == null)
      this.AttributeViewModel.IsEditEndAttachmentFrameEnabled = false;
    else
      this.AttributeViewModel.IsEditEndAttachmentFrameEnabled = true;
  }

  private void UpdateGenerateSensitivity(CApCableStatusMessageType messageType)
  {
    switch (messageType)
    {
      case CApCableStatusMessageType.Error:
      case CApCableStatusMessageType.Incomplet:
        this.DisableGenerateButton();
        break;
      case CApCableStatusMessageType.Warning:
      case CApCableStatusMessageType.None:
        if (this.IsEditMode)
        {
          if (this.HasCableDialogParametersChanged(this.Cable.CableData) || this.AttributeViewModel.CableName != ((ITxObject) this.Cable).Name)
          {
            if (this.CableController.CanCreateOrUpdateCable())
            {
              this.EnableGenerateButton();
              break;
            }
            this.DisableGenerateButton();
            break;
          }
          if (!this.IsCableValid || this.IsFrameBeingUpdated)
            break;
          this.DisableGenerateButton();
          break;
        }
        this.EnableGenerateButton();
        break;
    }
  }

  private void UpdateAttachmentFrameRegistry(ITxLocatableObject obj, ITxObject attachmentObj)
  {
    if (obj == null || this.IsFrameBeingUpdated)
      return;
    this.AttributeViewModel.CableStatusAnalysis.CableFrameAttachmentRetriever.UpdateFrameAttachmentRegistry(obj, attachmentObj as ITxLocatableObject);
  }

  public void UpdateAttachmentFrameRegistry(ITxLocatableObject obj)
  {
    if (obj == null)
      return;
    this.AttributeViewModel.CableStatusAnalysis.CableFrameAttachmentRetriever.UpdateFrameAttachmentRegistry(obj);
  }

  private void UpdateFrameEditorAfterCableModify()
  {
    this.frameBoxCtrlStartFrameCable.Object = (ITxObject) (this.Cable.StartFrame as TxFrame);
    this.frameBoxCtrlEndFrameCable.Object = (ITxObject) (this.Cable.EndFrame as TxFrame);
    this.AttributeViewModel.StartFrame = (ITxLocatableObject) (this.Cable.StartFrame as TxFrame);
    this.AttributeViewModel.EndFrame = (ITxLocatableObject) (this.Cable.EndFrame as TxFrame);
  }

  private void UpdateStatusBarMessage()
  {
    if (this.CableStatusMessageFactory != null)
    {
      if (TxApplication.ActiveDocument.SimulationPlayer.IsSimulationRunning())
      {
        ICApCableStatusMessage lengthErrorMessage = this.CableStatusMessageFactory.ComputeCableLengthErrorMessage();
        if (lengthErrorMessage.MessageType == CApCableStatusMessageType.Error)
        {
          this.AttributeViewModel.Message = lengthErrorMessage.MessageText;
          this.AttributeViewModel.StatusMessageType = lengthErrorMessage.MessageType;
        }
        else if (this.ErrorMessageStatusBeforeSimulationRunning != CApCableStatusMessageType.None)
        {
          this.AttributeViewModel.Message = this.ErrorMessageBeforeSimulationRunning;
          this.AttributeViewModel.StatusMessageType = this.ErrorMessageStatusBeforeSimulationRunning;
        }
      }
      else
      {
        this.AttributeViewModel.Message = "";
        this.AttributeViewModel.StatusMessageType = CApCableStatusMessageType.None;
        ICApCableStatusMessage priorityErrorMessage = this.CableStatusMessageFactory.ComputePriorityErrorMessage();
        this.AttributeViewModel.Message = priorityErrorMessage.MessageText;
        this.AttributeViewModel.StatusMessageType = priorityErrorMessage.MessageType;
      }
    }
    this.UpdateGenerateSensitivity(this.AttributeViewModel.StatusMessageType);
  }

  private void UpdateCableDialog(ITxCable cable)
  {
    this.IsFrameBeingUpdated = true;
    this.Cable = cable;
    this.UpdateCableDialog();
    this.SelectCurrentCable();
    this.IsFrameBeingUpdated = false;
  }

  private void UpdateCableDialog()
  {
    this.CableController.InitViewModelWithCable(this.Cable);
    this.AttachmentsUserControl.UpdateAttachmentDataListWithCable(this.Cable);
    if (this.frameBoxCtrlEndFrameCable.Object != this.AttributeViewModel.EndFrame)
    {
      this.frameBoxCtrlEndFrameCable.Object = (ITxObject) this.AttributeViewModel.EndFrame;
      this.UpdateEndAttachmentButtonSensitivity();
    }
    if (this.frameBoxCtrlStartFrameCable.Object != this.AttributeViewModel.StartFrame)
    {
      this.UpdateStartAttachmentButtonSensitivity();
      this.frameBoxCtrlStartFrameCable.Object = (ITxObject) this.AttributeViewModel.StartFrame;
    }
    this.AttachmentsUserControl.UpdateUserControl();
    this.ParametersUserControl.UpdateUserControl();
    if (this.Cable == null)
      return;
    this.IsEditMode = true;
    this.SwitchToEditMode();
  }

  private void UpdateRegistrationAttachmentFramesNotifications()
  {
    this.UnregisterAttachmentFrameNotifications();
    this.StartFrame = this.AttributeViewModel.StartFrame;
    this.EndFrame = this.AttributeViewModel.EndFrame;
    this.AttachmentFrames.Clear();
    foreach (CApFLEXAttachment rawAttachment in this.AttributeViewModel.RawAttachmentList())
      this.AttachmentFrames.Add(rawAttachment.FixedFrame);
    this.RegisterAttachmentFramesNotifications();
  }

  private void UpdateLinearUnitText()
  {
    this.labelCableLength.Text = CApFLEXStringTable.CableLengthLabel + CApCableUtility.LinearUnitLabelText();
    this.labelCableRadius.Text = CApFLEXStringTable.CableRadiusLabel + CApCableUtility.LinearUnitLabelText();
  }

  private void CloseDialog()
  {
    // ISSUE: explicit non-virtual call
    ((UIElement) this).KeyUp -= new System.Windows.Input.KeyEventHandler(this.m_keyup);
    this.txEditorName.Picked -= new TxObjEditBoxCtrl_PickedEventHandler(this.CableEditBoxCtrl_Picked);
    this.UnHighlightObjects();
    this.UnregisterFrameEditorEvent();
    this.UnregisterAttributViewModelPropertyChanged();
    this.UnregisterLinearUnitEvent();
    this.DidCloseUserControl();
    this.UnregisterCableEvents();
    this.UnregisterAttachmentFrameNotifications();
    this.UnregisterActiveDocumentEvent();
  }

  private void DidCloseUserControl()
  {
    this.AttachmentsUserControl.DidDialogClose();
    this.ParametersUserControl.DidDialogClose();
    if (this.AttachmentsUserControl.NewAttachmentWindow != null)
    {
      ((Window) this.AttachmentsUserControl.NewAttachmentWindow).Close();
      this.AttachmentsUserControl.NewAttachmentWindow = (CUiFLEXAttachmentEditorWindow) null;
    }
    if (this.AttachmentFrameWindow != null)
    {
      ((Window) this.AttachmentFrameWindow).Close();
      this.AttachmentFrameWindow = (CUiFLEXAttachmentFrameWindow) null;
    }
    this.UnregisterUserControlEvent();
  }

  private void UnHighlightObjects()
  {
    CApCableUtility.UnHighlightObject(this.AttributeViewModel.StartFrame as ITxDisplayableObject);
    CApCableUtility.UnHighlightObject(this.AttributeViewModel.EndFrame as ITxDisplayableObject);
    CApCableUtility.UnHighlightObject(this.AttributeViewModel.PassNearFrame as ITxDisplayableObject);
  }

  private void EnableGenerateButton()
  {
    if (this.AttributeViewModel.IsGenerateEnabled)
      return;
    this.AttributeViewModel.IsGenerateEnabled = true;
  }

  private void DisableGenerateButton()
  {
    if (!this.AttributeViewModel.IsGenerateEnabled)
      return;
    this.AttributeViewModel.IsGenerateEnabled = false;
  }

  private void ChangeGenerateButtonLabel(string newLabel)
  {
    this.btnGenerate.Content = (object) newLabel;
  }

  private void SwitchToEditMode()
  {
    this.IsEditMode = true;
    this.IsCableValid = true;
    this.DisableGenerateButton();
    this.ChangeGenerateButtonLabel(CApFLEXStringTable.FlexRegenerateButton);
    this.AttributeViewModel.IsCableEditable = (this.Cable as ITxComponent).IsOpenForModeling;
  }

  private void SwitchToCreateMode()
  {
    this.IsEditMode = false;
    this.IsCableValid = true;
    this.DisableGenerateButton();
    this.ChangeGenerateButtonLabel(CApFLEXStringTable.FlexGenerateButton);
    this.AttributeViewModel.IsCableEditable = true;
  }

  private bool CreateCable()
  {
    bool cable = false;
    using (new CApCableCursorChangeSession(System.Windows.Forms.Cursors.WaitCursor))
    {
      this.Cable = this.CableController.CreateCable();
      TxApplication.RefreshDisplay();
      if (this.Cable != null)
        cable = true;
    }
    return cable;
  }

  private bool UpdateCable(ref string errorMessage)
  {
    bool flag = true;
    errorMessage = "";
    using (new CApCableCursorChangeSession(System.Windows.Forms.Cursors.WaitCursor))
    {
      flag = this.CableController.UpdateCable(ref errorMessage);
      TxApplication.RefreshDisplay();
    }
    return flag;
  }

  private bool HasCableDialogParametersChanged(TxCableData cableData)
  {
    bool flag1 = false;
    if (this.TxNumericEditBoxLength != null && this.TxNumericEditBoxRadius != null && this.ParametersUserControl.AreParametersNumericalControlValid() && this.TxNumericEditBoxLength.Text != "" && this.TxNumericEditBoxRadius.Text != "" && this.ParametersUserControl.AreParametersNumericalControlTextValid())
    {
      flag1 = true;
      try
      {
        bool flag2 = Math.Abs(cableData.Length - CApCableUtility.ConvertStringToDouble(this.TxNumericEditBoxLength.Text) * TxApplication.Options.Units.LinearMultiplier) < 0.0001;
        bool flag3 = Math.Abs(cableData.Radius - CApCableUtility.ConvertStringToDouble(this.TxNumericEditBoxRadius.Text) * TxApplication.Options.Units.LinearMultiplier) < 0.0001;
        bool flag4 = this.ParametersUserControl.IsMaxTensionEqual(cableData.MaximumAllowedTension);
        bool flag5 = this.ParametersUserControl.IsDensityEqual(cableData.Density);
        bool flag6 = this.ParametersUserControl.IsYoungsModulusEqual(cableData.YoungsModulus);
        bool flag7 = this.ParametersUserControl.IsFulcrumLengthEqual(cableData.FulcrumLength);
        bool flag8 = this.ParametersUserControl.IsMaxTwistEqual(cableData.MaximumAllowedTwistRate);
        bool flag9 = this.ParametersUserControl.IsContactForceEqual(cableData.MaximumAllowedContactForce);
        bool flag10 = this.ParametersUserControl.IsCurvatureEqual(cableData.MinimumAllowedCurvatureRadius);
        bool flag11 = this.AttributeViewModel.IsMaxTwistAngleLimited == cableData.IsTwistRateLimited;
        bool flag12 = this.AttributeViewModel.IsMaxContactForceLimited == cableData.IsContactForceLimited;
        bool flag13 = this.AttributeViewModel.IsMinCurvatureRadiusLimited == cableData.IsCurvatureRadiusLimited;
        bool flag14 = this.Cable != null && this.AttributeViewModel.StartFrame == this.Cable.StartFrame && this.AttributeViewModel.EndFrame == this.Cable.EndFrame;
        if (flag14 && (this.Cable.StartFrame.AttachmentParent != this.AttributeViewModel.StartAttachPartTo || this.Cable.EndFrame.AttachmentParent != this.AttributeViewModel.EndAttachPartTo))
          flag14 = false;
        if (((!(this.txEditorName.Text == this.AttributeViewModel.CableName & flag14 & flag4 & flag2 & flag3 & flag5 & flag6 & flag7 & flag8 & flag9 & flag10) || cableData.Oscillation != this.AttributeViewModel.Oscillation || cableData.IsTwistRateLimited != this.AttributeViewModel.IsMaxTwistAngleLimited || cableData.IsCurvatureRadiusLimited != this.AttributeViewModel.IsMinCurvatureRadiusLimited || cableData.IsContactForceLimited != this.AttributeViewModel.IsMaxContactForceLimited ? 0 : (cableData.PassNearFrame == this.AttributeViewModel.PassNearFrame ? 1 : 0)) & (flag11 ? 1 : 0) & (flag12 ? 1 : 0) & (flag13 ? 1 : 0)) != 0)
        {
          List<TxCableAttachment> attachments1 = this.CableController.GetAttachments();
          List<TxCableAttachment> attachments2 = cableData.Attachments;
          if (attachments2.Count<TxCableAttachment>() == attachments1.Count)
          {
            bool flag15 = true;
            for (int index = 0; flag15 && index < attachments1.Count; ++index)
              flag15 = attachments2[index].Equals(attachments1[index]);
            flag1 = !flag15;
          }
        }
      }
      catch (FormatException ex)
      {
        flag1 = false;
      }
    }
    return flag1;
  }

  private bool CreateOrUpdateCable(
    CUiFLEXCableEditorWindow.UpdateCableOption updateOption)
  {
    bool orUpdateCable = false;
    this.IsCableCreatedAction = true;
    this.CableController.SaveAndUpdateParameterValues();
    bool flag = this.AreAttachmentsValid();
    if (!flag)
    {
      int num1 = (int) TxMessageBox.ShowModal(CApFLEXStringTable.CABLE_WITH_ATTACHMENTS_CREATION_FAIL, CApFLEXStringTable.CABLE_ERROR_DIALOG_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    bool sameRobot = this.AttributeViewModel.CableStatusAnalysis.AreStartEndFrameAttachedToSameRobot();
    if (!sameRobot)
    {
      int num2 = (int) TxMessageBox.ShowModal(CApFLEXStringTable.CABLE_FRAMES_ATTACHED_DISTINCT_ROBOTS, CApFLEXStringTable.CABLE_ERROR_DIALOG_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    if (flag & sameRobot)
    {
      if (this.IsEditMode)
      {
        if (updateOption == CUiFLEXCableEditorWindow.UpdateCableOption.DO_NOT_FORCE_UPDATE)
        {
          string errorMessage = "";
          if (this.CableController.AreCableDifferent(this.Cable, 0.0001) || !this.IsCableCreationSucceeded)
          {
            orUpdateCable = this.UpdateCable(ref errorMessage);
            if (orUpdateCable)
              this.IsCableCreationSucceeded = true;
          }
          else
            orUpdateCable = true;
          if (!orUpdateCable)
          {
            int num3 = (int) TxMessageBox.ShowModal(errorMessage, CApFLEXStringTable.CABLE_ERROR_DIALOG_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Hand);
          }
        }
        else
        {
          string errorMessage = "";
          orUpdateCable = this.UpdateCable(ref errorMessage);
          if (!orUpdateCable)
          {
            int num4 = (int) TxMessageBox.ShowModal(errorMessage, CApFLEXStringTable.CABLE_ERROR_DIALOG_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Hand);
          }
          this.UpdateFrameEditorAfterCableModify();
        }
      }
      else
      {
        try
        {
          orUpdateCable = this.CreateCable();
          if (orUpdateCable)
          {
            this.IsCableCreationSucceeded = true;
            this.UpdateFrameEditorAfterCableModify();
          }
          else
          {
            int num5 = (int) TxMessageBox.ShowModal(CApCableExceptionMessageProvider.ComputeDefaultGenerationErrorMessage(CApCableExceptionMessageProvider.CableAction.CREATION), CApFLEXStringTable.CABLE_ERROR_DIALOG_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Hand);
          }
        }
        catch (TxException ex)
        {
          this.IsCableCreationSucceeded = false;
          int num6 = (int) TxMessageBox.ShowModal(CApCableExceptionMessageProvider.ComputeCableExceptionErrorMessage(ex, CApCableExceptionMessageProvider.CableAction.CREATION), CApFLEXStringTable.CABLE_ERROR_DIALOG_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }
      }
    }
    this.IsCableCreatedAction = orUpdateCable;
    return orUpdateCable;
  }

  private bool AreAttachmentsValid()
  {
    bool flag = this.AttributeViewModel.CableStatusAnalysis.AreAttachmentsLengthSmallerThanCableLength();
    if (flag)
    {
      CApFLEXAttachmentErrorMessage errorMessage = (CApFLEXAttachmentErrorMessage) null;
      flag = this.AttributeViewModel.CableStatusAnalysis.ArePercentageLengthBetweenAttachmentsValid(out errorMessage);
    }
    return flag;
  }

  private void SelectCurrentCable()
  {
    if (this.Cable == null)
      return;
    TxObjectList txObjectList = new TxObjectList();
    ((Collection<ITxObject>) txObjectList).Add((ITxObject) this.Cable);
    TxApplication.ActiveSelection.SetItems(txObjectList);
    TxApplication.ActiveTemporarySelection.SetItems(txObjectList);
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected void NotifyPropertyChanged(string info)
  {
    if (this.PropertyChanged == null)
      return;
    this.PropertyChanged((object) this, new PropertyChangedEventArgs(info));
  }

  private void txEditorName_GotFocus(object sender, RoutedEventArgs e)
  {
    this.IsCableNameEditorBeingFocused = true;
    this.SelectCurrentCable();
    this.txEditorName.Text = this.AttributeViewModel.CableName;
    this.IsCableNameEditorBeingFocused = false;
  }

  private void attachStartFrame_Click(object sender, RoutedEventArgs e)
  {
    this.LaunchAttachmentFrame(FrameSelectionType.StartFrame);
  }

  private void attachEndFrame_Click(object sender, RoutedEventArgs e)
  {
    this.LaunchAttachmentFrame(FrameSelectionType.EndFrame);
  }

  private void LaunchAttachmentFrame(FrameSelectionType frameType)
  {
    this.AttachmentFrameWindow = new CUiFLEXAttachmentFrameWindow((ICApFLEXCableAttributeViewModel) this.AttributeViewModel, frameType);
    ((Window) this.AttachmentFrameWindow).Closing += new CancelEventHandler(this.AttachmentWindow_Closing);
    ((Window) this.AttachmentFrameWindow).Owner = (Window) this;
    ((Window) this.AttachmentFrameWindow).WindowStartupLocation = WindowStartupLocation.CenterOwner;
    ((Window) this.AttachmentFrameWindow).Show();
    ((UIElement) this).IsEnabled = false;
  }

  public void AttachmentWindow_Closing(object sender, CancelEventArgs e)
  {
    ((Window) this.AttachmentFrameWindow).Closing -= new CancelEventHandler(this.AttachmentWindow_Closing);
    this.AttachmentFrameWindow = (CUiFLEXAttachmentFrameWindow) null;
    ((UIElement) this).IsEnabled = true;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    System.Windows.Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/flexibles/windows/cuiflexcableeditorwindow.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  internal Delegate _CreateDelegate(Type delegateType, string handler)
  {
    return Delegate.CreateDelegate(delegateType, (object) this, handler);
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        this.dMainDialog = (CUiFLEXCableEditorWindow) target;
        ((FrameworkElement) this.dMainDialog).Loaded += new RoutedEventHandler(this.TxWindow_Loaded);
        ((Window) this.dMainDialog).Closing += new CancelEventHandler(this.TxWindow_Closed);
        break;
      case 2:
        this.createCableGrid = (Grid) target;
        break;
      case 3:
        this.cableNameRow = (RowDefinition) target;
        break;
      case 4:
        this.labelCableName = (TextBlock) target;
        break;
      case 5:
        this.txEditorName = (TxObjEditBoxControl) target;
        ((UIElement) this.txEditorName).GotFocus += new RoutedEventHandler(this.txEditorName_GotFocus);
        break;
      case 6:
        this.labelCableStartFrame = (TextBlock) target;
        break;
      case 7:
        this.startFrameGrid = (Grid) target;
        break;
      case 8:
        this.frameBoxCtrlStartFrameCable = (TxObjEditBoxControl) target;
        ((UIElement) this.frameBoxCtrlStartFrameCable).GotFocus += new RoutedEventHandler(this.StartFrame_GotFocus);
        ((UIElement) this.frameBoxCtrlStartFrameCable).LostFocus += new RoutedEventHandler(this.StartFrame_LostFocus);
        break;
      case 9:
        this.editStartAttachmentFrame = (System.Windows.Controls.Button) target;
        this.editStartAttachmentFrame.Click += new RoutedEventHandler(this.attachStartFrame_Click);
        break;
      case 10:
        this.labelCableEndFrame = (TextBlock) target;
        break;
      case 11:
        this.endFrameGrid = (Grid) target;
        break;
      case 12:
        this.frameBoxCtrlEndFrameCable = (TxObjEditBoxControl) target;
        ((UIElement) this.frameBoxCtrlEndFrameCable).GotFocus += new RoutedEventHandler(this.EndFrame_GotFocus);
        ((UIElement) this.frameBoxCtrlEndFrameCable).LostFocus += new RoutedEventHandler(this.EndFrame_LostFocus);
        break;
      case 13:
        this.editEndAttachmentFrame = (System.Windows.Controls.Button) target;
        this.editEndAttachmentFrame.Click += new RoutedEventHandler(this.attachEndFrame_Click);
        break;
      case 14:
        this.labelCableLength = (TextBlock) target;
        break;
      case 15:
        this.TxNumericEditBoxLength = (TxNumericEditBoxControl) target;
        ((UIElement) this.TxNumericEditBoxLength).GotFocus += new RoutedEventHandler(this.TxNumericEditBox_GotFocus);
        this.TxNumericEditBoxLength.TentativeValueChanged += new TxNumericEditBoxCtrl_TentativeValueChangedEventHandler(this.TxNumericEditBoxLength_TentativeValueChanged);
        break;
      case 16 /*0x10*/:
        this.labelCableRadius = (TextBlock) target;
        break;
      case 17:
        this.TxNumericEditBoxRadius = (TxNumericEditBoxControl) target;
        ((UIElement) this.TxNumericEditBoxRadius).GotFocus += new RoutedEventHandler(this.TxNumericEditBox_GotFocus);
        this.TxNumericEditBoxRadius.TentativeValueChanged += new TxNumericEditBoxCtrl_TentativeValueChangedEventHandler(this.TxNumericEditBoxRadius_TentativeValueChanged);
        break;
      case 18:
        this.ExpanderParameters = (Expander) target;
        this.ExpanderParameters.SizeChanged += new SizeChangedEventHandler(this.Expander_SizeChanged);
        break;
      case 19:
        this.ParametersUserControl = (CApCableParametersUserControl) target;
        break;
      case 20:
        this.ExpanderAttachments = (Expander) target;
        this.ExpanderAttachments.SizeChanged += new SizeChangedEventHandler(this.Expander_SizeChanged);
        break;
      case 21:
        this.AttachmentsUserControl = (CApCableAttachmentsUserControl) target;
        break;
      case 22:
        this.btnGenerate = (System.Windows.Controls.Button) target;
        this.btnGenerate.Click += new RoutedEventHandler(this.btnGenerate_Click);
        break;
      case 23:
        this.btnClose = (System.Windows.Controls.Button) target;
        this.btnClose.Click += new RoutedEventHandler(this.btnClose_Click);
        break;
      case 24:
        ((FrameworkElement) target).SizeChanged += new SizeChangedEventHandler(this.statusbar_SizeChanged);
        break;
      case 25:
        this.iMessageType = (System.Windows.Controls.Image) target;
        break;
      case 26:
        this.tbMessage = (TextBlock) target;
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }

  private enum UpdateCableOption
  {
    FORCE_UPDATE,
    DO_NOT_FORCE_UPDATE,
  }
}
